﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Psl.Chat;
using Psl.Applications;

namespace Stl.Chat.Components
{
    public partial class ChatCluster : UserControl
    {
        public ChatCluster()
        {
            InitializeComponent();

            Registry.MergeInMainMenu(menuStrip);
            Registry.MergeInMainTools(toolStrip);

            refreshAction.Enabled = false;
            clearAction.Enabled = false;
        }

        private void clearAction_Execute(object sender, EventArgs e)
        {
            ChatRegistry.ChatState.ModelInternal.Clear();
        }

        private void localClearAction_Execute(object sender, EventArgs e)
        {
            chatView.LocalClear();
        }

        private void refreshAction_Execute(object sender, EventArgs e)
        {
            chatView.RefreshView();
        }

        private void activeBar_ActiveChanged(object sender, EventArgs e)
        {
            bool active = activeBar.IsActive;
            if (!active) toolStrip.Visible = false;
            actionList.Visible = active;
            if (active) toolStrip.Visible = true;
        }

        private void applicationEvents_ApplicationIdle(object sender, EventArgs e)
        {
            localClearAction.Enabled = !chatView.IsEmpty;
        }

        private void chatEvents_ChatOpened(object sender, EventArgs e)
        {
            refreshAction.Enabled = true;
            clearAction.Enabled = true ;
        }

        private void chatEvents_ChatClosing(object sender, EventArgs e)
        {
            refreshAction.Enabled = false;
            clearAction.Enabled = false;
        }
    }
}
